#pragma once
#include"RBTree.h"

namespace yzcmap
{
	template<class K, class V>
	class map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public: 
		typedef typename RBTree<K, pair<K, V>, MapKeyOfT>::iterator iterator;

		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		bool Insert(const pair<K, V>& kv)
		{
			return _t.Insert(kv);
		}

		void InOrder()
		{
			_t.InOrder();
		}
	private:		


		RBTree<K, pair<K, V>, MapKeyOfT> _t;
	};

	void test()
	{
		map<int, pair<int, string>> m{};
		m.Insert(make_pair(7, make_pair(7, "seven")));
		m.Insert(make_pair(8, make_pair(8, "eight")));
		m.Insert(make_pair(1, make_pair(1, "one")));
		m.Insert(make_pair(4, make_pair(4, "four")));
		m.Insert(make_pair(6, make_pair(6, "size")));
		m.Insert(make_pair(9, make_pair(9, "nine")));
		m.Insert(make_pair(5, make_pair(5, "five")));
		m.Insert(make_pair(10, make_pair(10, "ten")));	
		m.Insert(make_pair(2, make_pair(2, "two")));
		m.Insert(make_pair(3, make_pair(3, "three")));
		//m.InOrder();
		auto it = m.begin();
		while (it != m.end())
		{
			cout << it->first << "   " << it->second.first << ":" << it->second.second << endl;
			++it;
		}
	}
}

